package Views;

import Models.Customer;
import java.util.ArrayList;
import javax.swing.table.DefaultTableModel;

/**
 * @author Erik Barrett
 */
public class CustomerTableModel extends DefaultTableModel
{
	private ArrayList<Customer> customers;
    
	public CustomerTableModel()
    {
		this.customers = new ArrayList<Customer>();
    }
    
	public CustomerTableModel(ArrayList<Customer> customers)
    {
		this.customers = customers;
    }

    @Override
	public boolean isCellEditable(int row, int column)
	{
		return false;
	}
    
    public void setData(ArrayList<Customer> customers)
	{
		this.customers = customers;
		fireTableDataChanged();
	}

    public ArrayList<Customer> getData()
	{
        return this.customers;
	}
    
    @Override
	public int getColumnCount()
	{
        return 4;
	}
    
    @Override
    public int getRowCount()
	{
		if(this.customers == null)
		{
			return 0;
		}
        else
		{
            return this.customers.size();
		}
	}
    
	@Override
	public String getColumnName(int column)
	{
		String columnName = "";
		switch(column)
		{
			case 0:
				columnName = "ID";
				break;
			case 1:
				columnName = "Navn";
				break;
			case 2:
				columnName = "CVR";
				break;
			case 3:
				columnName = "Tlf";
				break;
		}
		return columnName;
	}

	@Override
	public Object getValueAt(int row, int column)
	{
		Object value = null;
		switch(column)
		{
			case 0:
				value = this.customers.get(row).getCustomerNo();
				break;
			case 1:
				value = this.customers.get(row).getName();
				break;
			case 2:
				value = this.customers.get(row).getCvr();
				break;
			case 3:
				value = this.customers.get(row).getPhoneNo();
				break;			
		}
		return value;
	}
}
